<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>收银宝</title>
		<link rel="stylesheet" href="dist/css/layui.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/shouy.css" />
		<style>
			.np_price{
			    color: #000000;
			    height: 45px;
			    border: 0;
			    width:200px;
			    border-radius: 25px;
			    background: #F0F0F0;
			    font-size: 14px;
			    line-height: 45px;
			    text-align: center;
			}
			.mui-popup-input textarea{margin-top: 5px;height: 100px; display: block; width: 90%; font-size: 14px;}
			.mui-popup-input textarea{padding: 5px;}
			.mui-popup-text{font-size: 16px; line-height: normal; padding-bottom: 5px; text-align: left;}
			.mui-popup-inner{position: relative; padding: 25px 15px 0; border-radius: 13px 13px 0 0; background: white;}
			.mui-popup {position: fixed; z-index: 10000; top: 40%; left: 50%; display: none; overflow: hidden; width: 470px;-webkit-transition-property: -webkit-transform, opacity; transition-property: transform, opacity; -webkit-transform: translate3d(-50%, -50%, 0) scale(1.185); transform: translate3d(-50%, -50%, 0) scale(1.185); text-align: center; opacity: 0; color: #000; border-radius: 13px;}
			.mui-popup.mui-popup-in {display: block; -webkit-transition-duration: 400ms; transition-duration: 400ms; -webkit-transform: translate3d(-50%, -50%, 0) scale(1); transform: translate3d(-50%, -50%, 0) scale(1); opacity: 1;}
			.mui-popup-buttons {position: relative; border-top: 1px solid #E6E6E6; display: -webkit-box; display: -webkit-flex; display: flex; height: 44px; -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center;}
			.mui-popup-button {font-size: 17px; line-height: 44px; position: relative; display: block; overflow: hidden; box-sizing: border-box; width: 50%; float: left; height: 44px; padding: 0 5px; cursor: pointer; text-align: center; white-space: nowrap; text-overflow: ellipsis; color: #007aff; background: white; -webkit-box-flex: 1; *width: 46%; *float: left;}			
			.mui-popup-button:first-child {border-radius: 0 0 0 13px; border-left: 1px solid #E6E6E6;}
			.mui-popup-button:last-child {border-radius: 0 0 13px;}
			.mui-popup-button.mui-popup-button-bold {font-weight: 600;}
			.mui-popup-backdrop {position: fixed; z-index: 998; top: 0; right: 0; bottom: 0; left: 0; -webkit-transition-duration: 400ms; transition-duration: 400ms; opacity: 0; background: rgba(0, 0, 0, .4); *background: #000000; *opacity:0.9; *filter:alpha(opacity=9);}
			.mui-popup-backdrop.mui-active {opacity: 1;}
			.xhd_list li {width: 90%;margin: 0 auto;box-shadow: 0 0 15px 0 #CCCCCC;border-radius: 5px; padding: 5% 5%;margin-bottom: 15px;}
			.xhd_list p{font-size: 18px;}
			#xf_price{font-size: 2.5rem;}
			.xz_bz{color:#908a8a}
			.active{background: #2783e7;}
			.active p{color:#FFFFFF}
		</style>
	</head>

	<body>
		<div class="wrap">
			<div class="sy_header clearfix">
				<div class="sy_hleft">
					<ul class="sy_nav clearfix">
						<li class="active">
							<a href="index.html">
								<div class="iconfont icon-shouyintai"></div>
								<p>工作台</p>
							</a>
						</li>
						<li>
							<a href="orders.html">
								<div class="iconfont icon-saomashouyin"></div>
								<p>订单流水</p>
							</a>
						</li>
						<li>
							<a href="yd.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>预定管理</p>
							</a>
						</li>
						<li>
							<a href="jiaoban.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>交班</p>
							</a>
						</li>
						<li>
							<a href="set.html">
								<div class="iconfont icon-weibiaoti-"></div>
								<p>设置</p>
							</a>
						</li>
					</ul>
				
				</div>
				<div class="sy_hright">
					<div class="sy_shopbox">
						<div class="sy_simg"><img id="toux" src="" style="background-color: #FFFFFF;"></div>
						<div class="sy_sinfo">
							<p class="sy_snam">店名：<span id="sname"></span></p>
							<p>用户：<span id="user"></span></p>
							<p class="exit" onclick="exit()">退出登陆</p>
						</div>
					</div>
				</div>
				
			</div>

			<div class="sy_conbox clearfix">
				<div class="sy_fleft">
					<div class="sy_flbox">
						<div class="sy_fnumbox">
							<div class="sy_fsrkbox clearfix">
								<div class="sy_fsrkr"><input onkeyup="keyup(this)" type="text" id="price" name="price" placeholder="输入消费金额"></div>
							</div>
							<div class="sy_fyx">
								<input class="np_price" onkeyup="keyup(this)" type="text" id="np_price" name="np_price" placeholder="输入不参与优惠的金额">
							</div>
						</div>
						<div class="sy_fbtnbox clearfix">
							<button type="button" onclick="jiz_tck()" class="sy_fbtn blue">记账收款</button>
							<button type="button" onclick="sao_pay()" class="sy_fbtn blue">扫一扫收款</button>
							<button type="button" onclick="card_pay()" class="sy_fbtn blue">会员卡收款</button>
							
						</div>
					</div>
				</div>
				<div class="sy_fright">
					<div class="sy_frbox">
						<div class="sy_frbt">今日收银</div>
						<ul class="sy_frlist clearfix">
							<li>
								<p class="sy_frsybt">实收金额</p>
								<p class="sy_frsybum"><em id="yye">0.00</em></p>
							</li>
							<li>
								<p class="sy_frsybt">房券核销</p>
								<p class="sy_frsybum"><em id="yh">0.00</em></p>
							</li>
							<li>
								<p class="sy_frsybt">记账</p>
								<p class="sy_frsybum"><em id="jz">0.00</em></p>
							</li>
							<li>
								<p class="sy_frsybt">扫码</p>
								<p class="sy_frsybum"><em id="sm">0.00</em></p>
							</li>
						</ul>
					</div>
				</div>
			</div>
			
			
			<div class="bt_name">鸿运集团酒店欢迎您</div>
		</div>
		
		<!--会员卡收款-->
		<div id="tanchu" style=" position: relative; width: 960px;display: none; ">
		<div class="mui-popup mui-popup-in" style="display: block;">
			<div class="mui-popup-inner">
				<div class="mui-popup-text" style="text-align: center;">会员卡收款</div>
				<div class="mui-popup-text" style="text-align: left;">消费金额:￥<em id="s_price">100</em></div>
				<div class="mui-popup-text" style="color: red;padding: 5px 3px;font-size: 14px;" >温馨提示：请会员出示动态会员码,打开鸿运酒店公众号-我的-会员码</div>
				<div class="mui-popup-input"><input class="layui-input" id="no" placeholder="请输入或扫描动态会员码"/></div>
				<div id="user_msg" style="display: none;">
					<div class="mui-popup-text2"><div class="left">会员</div><div class="right" id="name">0</div></div>
					<div class="mui-popup-text2"><em class="left">折扣</em><em class="right"  id="zkou">0</em></div>
					<div class="mui-popup-text2"><em class="left">消费金额</em><em class="right" id="origin_price">0</em></div>
					<div class="mui-popup-text2"><em class="left">折扣金额</em><em class="right" id="zk_price">0</em></div>
					<div class="mui-popup-text2"><em class="left">实际支付金额</em><em class="right" id="pay_price">0</em></div>
					<div class="mui-popup-text2"><em class="left">会员卡余额</em><em class="right" id="card_balance">0</em></div>
				</div>
			</div>
			<div class="mui-popup-buttons clearfix"><span class="mui-popup-button" onclick="cans()">取消</span><span onclick="get_userinfo()" class="mui-popup-button mui-popup-button-bold">确认收款</span></div>
		</div>
		<div class="mui-popup-backdrop mui-active" style="display: block;"></div>
		</div>
		
		<!--记账收款-->
		<div id="jiz" style=" position: relative; width: 960px;display: none; ">
		<div class="mui-popup mui-popup-in" style="display: block;">
			<div class="mui-popup-inner">
				<div class="mui-popup-text" style="text-align: center;"><em id="xf_price">100</em>元</div>
				<div class="mui-popup-text xz_bz" style="text-align: left;">请选择一种方式记账，并向用户收款:</div>
				<div id="user_msg">
					<div class="mui-popup-text2">
						<ul class="hycz_list xhd_list">
						<!--选择记账方式-->
							<li data-val="8">
								<p class="name">银行卡记账</p>
							</li>
							<li data-val="1">
								<p class="name">现金记账</p>
							</li>
						</ul>
					</div>
				</div>
			</div>
			<div class="mui-popup-buttons clearfix"><span class="mui-popup-button" onclick="javascript:$('#jiz').hide()">取消</span><span class="mui-popup-button mui-popup-button-bold que_pay">确认</span></div>
		</div>
		<div class="mui-popup-backdrop mui-active" style="display: block;"></div>
		</div>
		
		<!--扫一扫收款-->
		<div id="sys_sk" style=" position: relative; width: 960px;display: none; ">
		<input type='hidden' id='is_sys' value='0'/>
		<div class="mui-popup mui-popup-in" style="display: block;">
			<div class="mui-popup-inner">
				<div class="mui-popup-text" style="text-align: center;">扫一扫收款</div>
				<div class="mui-popup-text" style="text-align: left;">应收金额:￥<em id="sys_price">100</em></div>
				<div class="mui-popup-input"><input class="layui-input" id="fk_code" placeholder="付款码"/></div>
				<div id="user_msg" style="display: none;">
					<div class="mui-popup-text2"><div class="left">会员</div><div class="right" id="name">0</div></div>
					<div class="mui-popup-text2"><em class="left">折扣</em><em class="right"  id="zkou">0</em></div>
					<div class="mui-popup-text2"><em class="left">消费金额</em><em class="right" id="origin_price">0</em></div>
					<div class="mui-popup-text2"><em class="left">折扣金额</em><em class="right" id="zk_price">0</em></div>
					<div class="mui-popup-text2"><em class="left">实际支付金额</em><em class="right" id="pay_price">0</em></div>
					<div class="mui-popup-text2"><em class="left">会员卡余额</em><em class="right" id="card_balance">0</em></div>
				</div>
			</div>
			<div class="mui-popup-buttons clearfix"><span class="mui-popup-button" onclick="sys_over()">取消</span><span onclick="sys_zf()" class="mui-popup-button mui-popup-button-bold">确认收款</span></div>
		</div>
		<div class="mui-popup-backdrop mui-active" style="display: block;"></div>
		</div>
		
		
		<input type="hidden" id="user_id"  />
	</body>

</html>
<script type="text/javascript" src="dist/jquery-1.11.0.min.js"></script>
<script src="dist/json2.js"></script>
<script src="dist/layui.all.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">
document.onkeydown = function(e) {
//捕捉回车事件
 var ev = (typeof event!= 'undefined') ? window.event : e;
 if(ev.keyCode == 13) {
 	if($('#is_sys').val()==1){
 		sys_zf();
 		return;
 	}
  	get_userinfo();
 }
}

var isFrist = true;
function get_userinfo(){
	var user_id = $('#user_id').val();
	if(Number(user_id)>0){
		shouku();
		return;
	}
	$.ajax({
			url: APP.path + "index/get_userinfo",
			type:"POST",
			data: {
				no: $("#no").val(),
				app_id: APP.app_id,
				time: Date.parse(new Date()),
				store_id:getValue('store_name_id')
			},
			success: function(data) {
				if(data.code!=200){
					layer.msg(data.msg);
				}else{
					console.log(data);
					
					var user=data.user;
					$("#user_id").val(user.id);
					var levle=data.level;
					$("#name").text(user.user_name);
					var price=parseFloat($("#s_price").text());
					var np_price= Number($("#np_price").val());
					if(levle){
						var zk = (levle.discount)/100;
						$("#zkou").text(zk+'折');
						var zk_price=(price-np_price)*zk;
						var pay_price=(price-np_price)-zk_price+np_price;
					}else{
						$("#zkou").text(0);
						var pay_price=price;
						var zk_price=0;
					}
					
					$("#origin_price").text(price.toFixed(2));
					$("#zk_price").text(zk_price.toFixed(2));
					$("#pay_price").text(pay_price.toFixed(2));
					$("#card_balance").text(user.balance);
					$("#user_msg").show();
				}
			}
	})
}
function cans(){
	$("#tanchu").hide();

}
function card_pay(){
		var price = parseFloat($("#price").val());
		var np_price = Number($("#np_price").val());
		if(price == "" || isNaN(price)) {
			layer.msg("请输入正确的账单金额!");
			return false;
		}
		if(np_price != "" && (np_price>price)) {
			layer.msg("不参与优惠金额不能大于总金额!");
			return false;
		}
	$("#tanchu").show();
	$("#s_price").text(price);
	$("#no").val("");
}
function shouku(){
	var price = parseFloat($("#price").val());
	var con = layer.confirm('确认操作?', function(index) {
		if(isFrist==true){
			isFrist=false;
			$.ajax({
				type:'post',
				url: APP.path + "index/shouk",
				data: {
					price:$("#price").val(),
					np_price: Number($("#np_price").val()),
					user_id:$("#user_id").val(),
					store_id: getValue("store_name_id"),
					app_id: APP.app_id,
					time: Date.parse(new Date()),
					staff_id:getValue('id')
				},
				success: function(data) {
						if(data.code==200){
							layer.close(con);
							$("#tanchu").hide();
							$('#user_msg').hide();
							jz_common(data,price,1);
							get_work();
							$("#np_price").val('');
						}else{
								layer.msg(data.msg);
						}
						isFrist=true;
					}
				})
		}else{
			layer.msg('请勿频繁操作！');
		}
	});
}

//记账收款
function jiz_tck(){
	var price = parseFloat($("#price").val());
		if(price == "" || isNaN(price)) {
			layer.msg("请输入正确的账单金额!");
			return false;
		}
	$('#jiz').show();
	$("#xf_price").text(price);
}


//记账收款
	$(".hycz_list li").click(function(){
		$(".active").removeClass("active");
		$(this).addClass("active");
	})
	
	$(".que_pay").click(function(){
		var jz_type=$(".active").data("val");
		var price =$("#xf_price").text();
		if(jz_type==undefined){
			layer.msg("请选择记账方式");
			return;
		}
		if(isFrist==true){
			isFrist=false;
			$.ajax({
				type: "post",
				url:  APP.path + "index/jz_pay",
				data: {
					balance:price,
					pay_type:jz_type,
					store_id: getValue("store_name_id"),
					staff_id:getValue('id')
				},
				success: function(data) {
					if(data.code==200){
						$('#jiz').hide();
						jz_common(data,price,1);
						get_work();
					}else{
						layer.msg(data.msg);
					}
					isFrist=true;
				}
			})
		}else{
			layer.msg('请勿频繁操作！');
		}
		
		
	})
	
	//扫一扫收款
	function sao_pay(){
		var price = parseFloat($("#price").val());
		if(price == "" || isNaN(price)) {
			layer.msg("请输入正确的账单金额!");
			return false;
		}
		$('#is_sys').val(1);
		$('#sys_sk').show();
		$("#sys_price").text(price);
	}
	function sys_zf(){
		var price = parseFloat($("#price").val());
		var mem_card = $("#fk_code").val();
		if(mem_card == "") {
			layer.msg("付款码不可为空!");
			return false;
		}
		if(isFrist==true){
			isFrist=false;
			$.ajax({
				type: "post",
				url:  APP.path + "index/sys_pay",
				data: {
					balance:parseFloat($("#price").val()),
					store_id: getValue("store_name_id"),
					staff_id:getValue('id'),
					mem_card:mem_card
				},
				success: function(data) {
					if(data.code==200){
						$('#sys_sk').hide();
						jz_common(data,price,1);
						get_work();
					}else{
						layer.msg(data.msg);
					}
					isFrist=true;
				}
			})
		}else{
			layer.msg('请勿频繁操作！');
		}
		
	}
	
	$(function(){
		get_work();
	});
	
	function get_work(){
		$.ajax({
			type: "post",
			url:  APP.path + "index/get_work",
			data: {
				id: getValue("id"),
				log_time:getValue('login_time')
			},
			success: function(data) {
				var log = data.emp;
				$('#yye').text(log.balance);
				$('#sm').text(log.sm);
				$('#yh').text(log.hx);
				$('#jz').text(log.jz);
				
			}
		})
	}
	
	//扫一扫关闭
	function sys_over(){
		$('#is_sys').val(0);
		$('#sys_sk').hide();
	}

</script>